package com.xiaohao.communication.controller;

import com.xiaohao.communication.bean.ExpertInfo;
import com.xiaohao.communication.mobileUtil.SendCode;
import com.xiaohao.communication.service.UserDetailInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/*
*用户详细信息完善
* */
@Controller
public class UserDetailInfoController {


    @Autowired
    SendCode sendCode;

    @Autowired
    UserDetailInfoService userDetailInfoService;


    //发送验证码到手机，并且用session保存验证码，并且保存手机号
    @GetMapping("/send-code")
    public void sendPhoneNumberCode(String phoneNumber, HttpSession session,int id){
        try {

            String s = sendCode.sendPhoneNumberCode(phoneNumber);
            session.setAttribute("code",s);

            //根据id 保存手机号
            userDetailInfoService.addPhone(id,phoneNumber);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /*              待完善
    * 验证手机号
    * 用户将验证码输入，在工具类中将此验证码与服务器中验证码对比。
    * */
    @GetMapping("/add-phone")
    public void verifyCode(String code){
        sendCode.verifyVode(code);
    }


    /*
    *  添加专家认证的信息   带有嵌套对象 ,和原来一样        success
    * */
    @ResponseBody
    @GetMapping("/add-expert")
    public void addExpert(ExpertInfo expertInfo){
        userDetailInfoService.addExpert(expertInfo);
    }

}
